<?php
error_reporting(1);
include("../lib/config.php");
include("../lib/var.php");

if(isset($_GET['delete'])){
	mssql_query("DELETE FROM Jenjang WHERE id='".$_GET['id']."'");
}

if(isset($_POST['Submit']) && $_POST['id']!=""){
	//Edit
	echo "edit";
	mssql_query("UPDATE Jenjang SET nama='".$_POST['jenjang']."' WHERE id='".$_POST['id']."'");
}elseif(isset($_POST['Submit']) && $_POST['id']==""){
	//Add
	mssql_query("INSERT INTO Jenjang (nama) VALUES('".$_POST['jenjang']."')");
}

if(isset($_GET['edit'])){
	@list($nama) = mssql_fetch_row(mssql_query("SELECT nama FROM jenjang WHERE id='".$_GET['id']."'"));
}
?>
<link rel="stylesheet" type="text/css" href="<?=$path?>/style/style.css" />
<script language="javascript" src="<?=$path?>/js/event.js"></script>
<script language="javascript" src="<?=$path?>/js/calendar.js"></script>
<script language="javascript" src="<?=$path?>/js/jquery.min.js"></script>
<script language="javascript" src="<?=$path?>/js/apps.js"></script>
<script language="javascript">
function Validation(){
	if ($("#jenjang").val() == ''){
		alert('Jenjang Harus diisi');
		document.FrmJenjang.jenjang.focus();
		return false;
	}else{
		return true;
	}
}
</script>

<strong style="background-color: rgb(0, 51, 153); color: rgb(255, 255, 255); padding:2 2 2 2;">JENJANG PENDIDIKAN</strong>
<hr color="#FFFFFF" noshade>
<body bgcolor="#FFFFFF">
<form method="post" name="FrmJenjang" onSubmit="return Validation()">
<table>
    <tr>
        <td width="100"><strong>JENJANG</strong></td>
        <td>
            :<input class="text" id="jenjang" type="text" name="jenjang" style="font-weight: bold;" value="<?php if(isset($_GET['edit'])) echo $nama; ?>"/>
            <input type="hidden" name="id" value="<?php if(isset($_GET['edit'])) echo $_GET['id']; ?>"/>
            <span class="required">*</span>
        </td>
        <td align="right"><input class="button" name="Clear" type="button" onClick="javascript:window.location='frm_add_jenjang.php'" value="Clear"/><input class="button" name="Submit" type="submit" onClick="" value="Save"/></td>
    </tr>
</table>
</form>
<table width='100%'>
    <tr class=headlist>
        <td width=2%>No.</td>
        <td width=15%>Jenjang</td>
        <td width=7%>Manage</td>
    </tr>

<?php
	$sql	= "SELECT * FROM Jenjang"; 
	$dJenjang = mssql_query($sql,$conn);
	$no = 1;
	while($dtJ = mssql_fetch_array($dJenjang)){
		echo "
		<tr class=contentlist>
			<td width=2% align=center>$no</td>
			<td width=15%>$dtJ[nama]</td>
			<td width=2% align=center>
				<a href=\"frm_add_jenjang.php?edit&id=$dtJ[id]\">
				<img border=\"0\" alt=\"Edit\" title=\"Edit\" src=\"../images/b_edit.png\"/>
				</a>
				<a href=\"frm_add_jenjang.php?delete&id=$dtJ[id]\">
				<img border=\"0\" alt=\"Delete\" title=\"Delete\" src=\"../images/b_delete.png\"/>
				</a>			
			</td>
		</tr>		
		";
		$no++;
	}
?>

</body>